/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package menus;

import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import java.io.IOException;
import java.io.InputStream;
import util.Menu;

/**
 *
 * @author nialldeasy
 */
public class Reader extends Menu {

    String Name = "";
    public Reader(String name){
        Name=name;

    } 
    public void recycleBin() {
      
    }

    protected void execute(Form f) {

        //.....................add Image for text file if available......//
        this.setBackround("paper.jpg");
        try {
            Label image = new Label(Image.createImage("/images/" + Name + ".jpg"));
            if (image != null) {
                f.addComponent(image);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        try{
        
         String str = readFile(Name);

         if(str != null){
            addText(str, f);
         } else {
             addText("No information available", f);
         }

        this.setLayout(1);
        } catch(Exception ex){
            ex.printStackTrace();
        }



    }

    public void addText(String text, Form f) {
        TextArea t = new TextArea(text);
        t.setEditable(false);
        f.addComponent(t);
    }

   public String readFile(String name) {
        InputStream is = getClass().getResourceAsStream("/Landmarks/" + Name);
                        StringBuffer sb = new StringBuffer();
        try {
            int chars, i = 0;
            while ((chars = is.read()) != -1) {
                sb.append((char) chars);
            }
            return sb.toString();
        } catch (Exception e) {
        }
        return null;
    }
}
